package com.lyshop.jinxiang.view;

import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.lyshop.jinxiang.R;
import com.lyshop.jinxiang.adapters.LevelPopAdapter;
import com.lyshop.jinxiang.base.BaseActivity;
import com.lyshop.jinxiang.base.BasePopUpWindow;

import java.util.ArrayList;
import java.util.List;


public class LevelPopupWindow extends BasePopUpWindow implements View.OnClickListener {


    private LevelPopupListener mListener;
    private BaseActivity mActivity;
    private GridView gv_product;
    private LevelPopAdapter mAdapter;
    private List<String> mList;

    public LevelPopupWindow(BaseActivity a, LevelPopupListener listener) {
        super(a, R.layout.layout_popup_pro_bean);
        setBackgroundColor(0x00000000);
        this.mActivity = a;
        this.mListener = listener;
        gv_product = getPopUpView().findViewById(R.id.gv_product);
        getPopUpView().setOnClickListener(this);
        setGv_product();

    }

    private void setGv_product() {
        if (null == mAdapter) {
            mList = new ArrayList<>();
            mList.add("大众会员");
            mList.add("青铜会员");
            mList.add("白银会员");
            mList.add("黄金会员");
            mList.add("铂金会员");
            mList.add("钻石会员");
            mList.add("黑钻会员");
            mAdapter = new LevelPopAdapter(mActivity, mList);
            gv_product.setAdapter(mAdapter);
        }
        gv_product.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String levelName = mList.get(position);
                mAdapter.setChecked(position);
                mAdapter.notifyDataSetChanged();
                mListener.onClickLevel(levelName, position + 1);
                dismiss();
            }
        });
    }

    public void resetChoose() {
        mAdapter.setChecked(-1);
    }

    @Override
    public void onClick(View v) {
        dismiss();
    }

    public interface LevelPopupListener {
        void onClickLevel(String name, int level);
    }
}
